package com.lemon.bean;

import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.MenuItem;

public class MyMenuContext extends ContextMenu {
    private final MenuItem copy = new MenuItem("复制");
    private final MenuItem paste = new MenuItem("粘贴");
    private final MenuItem rename = new MenuItem("重命名");
    private final MenuItem delete = new MenuItem("删除");

    //私有化
    private MyMenuContext() {
        this.getItems().addAll(copy,paste,rename,delete);
    }

    private static MyMenuContext instant = null;

    public void setCopyFunction(EventHandler<ActionEvent> handler){
        copy.setOnAction(handler);
    }
    public void setPasteFunction(EventHandler<ActionEvent> handler){
        paste.setOnAction(handler);
    }
    public void setRenameFunction(EventHandler<ActionEvent> handler){rename.setOnAction(handler);}
    public void setDeleteFunction(EventHandler<ActionEvent> handler){
        delete.setOnAction(handler);
    }

    //单例模式懒汉式
    public static MyMenuContext getInstant() {
        if (instant == null) {
            instant = new MyMenuContext();
        }
        return instant;
    }

}
